\defmodule {ChiSquareNoncentralGamGen}

This class implements {\em noncentral chi square\/} random variate generators
using the additive property of the noncentral chi square distribution
\cite{tKRI06a}. It uses the following algorithm: generate a real
 $X \sim N(\sqrt\lambda, 1)$ from a normal distribution with variance 1,
generate a real $Y \sim \Gamma((\nu - 1)/2, 1/2)$ from a gamma distribution,
then return $X^2 + Y$. Here $\nu$ is the number of degrees of freedom and
$\lambda$ is the noncentrality parameter.

To generate the normal variates, one uses the fast
\emph{acceptance-complement ratio} method in \cite{rHOR90a}
(see class \externalclass{umontreal.iro.lecuyer.randvar}{NormalACRGen}).
To generate the gamma variates, one uses acceptance-rejection for $\alpha<1$,
and acceptance-complement for $\alpha\ge 1$, as proposed in \cite{rAHR72b,rAHR82a}
(see class \externalclass{umontreal.iro.lecuyer.randvar}
{GammaAcceptanceRejectionGen}).

This noncentral chi square generator is faster than the generator
\externalclass{umontreal.iro.lecuyer.randvar}{ChiSquareNoncentral\-PoisGen}
\begin{latexonly}on the next page of this guide\end{latexonly}.
For small $\lambda$, it is nearly twice as fast. As $\lambda$ increases,
it is still faster but not as much.


\bigskip\hrule

\begin{code}
\begin{hide}
/*
 * Class:        ChiSquareNoncentralGamGen
 * Description:  noncentral chi-square random variate generators using the
                 additive property of the noncentral chi-square distribution
 * Environment:  Java
 * Software:     SSJ
 * Copyright (C) 2001  Pierre L'Ecuyer and Universite de Montreal
 * Organization: DIRO, Universite de Montreal
 * @author       Richard Simard
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   <a href="http://www.gnu.org/licenses">GPL licence site</a>.
 */
\end{hide}
package umontreal.iro.lecuyer.randvar;\begin{hide}
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.probdist.*;
\end{hide}

public class ChiSquareNoncentralGamGen extends ChiSquareNoncentralGen \begin{hide} {
   private double racLam = -1.0;

\end{hide}\end{code}

\subsubsection* {Constructor}

\begin{code}

   public ChiSquareNoncentralGamGen (RandomStream stream,
                                     double nu, double lambda) \begin{hide} {
      super (stream, null);
      setParams (nu, lambda);
      racLam = Math.sqrt(lambda);
   }\end{hide}
\end{code}
\begin{tabb}  Creates a noncentral chi square random variate generator with
 with $\nu = $ \texttt{nu} degrees of freedom and noncentrality parameter
$\lambda = $ \texttt{lambda} using stream \texttt{stream}, as described above.
\end{tabb}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
\subsubsection* {Methods}
\begin{code}\begin{hide}

   public double nextDouble() {
      return gamGen (stream, nu, racLam);
   }\end{hide}

   public static double nextDouble (RandomStream stream,
                                    double nu, double lambda) \begin{hide} {
      double racLam = Math.sqrt(lambda);
      return gamGen (stream, nu, racLam);
   }\end{hide}
\end{code}
 \begin{tabb}  Generates a variate from the noncentral chi square
   distribution with parameters $\nu = $~\texttt{nu} and $\lambda =
   $~\texttt{lambda} using stream \texttt{stream}, as described above.
 \end{tabb}
\begin{code}\begin{hide}

//>>>>>>>>>>>>>>>>>>>>  P R I V A T E    M E T H O D S   <<<<<<<<<<<<<<<<<<<<

   private static double gamGen (RandomStream s, double nu, double racLam) {
      // racLam = sqrt(lambda)
      double x = NormalACRGen.nextDouble (s, racLam, 1.0);
      double y = GammaAcceptanceRejectionGen.nextDouble(s, 0.5*(nu - 1.0), 0.5);
      return x*x + y;
   }

}\end{hide}
\end{code}
